<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">

        <h2>View Supplier Rankings</h2>
        <h:form id="viewSupplierListForm" style="font-size: 85%">
            <p:panel >
                <p:messages/>
                <br/>
                <h:panelGrid columns="3" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Select Raw Material"/>
                    <p:inputText id="rawMaterial" value="#{rankingManagerBean.rm.name}" disabled="true"/>
                    <p:commandButton image="ui-icon ui-icon-search" oncomplete="rawMaterialDialog.show()"/>

                    <h:outputLabel style="font-weight: bold" value="Select Criteria"/>
                    <h:selectOneMenu value ="#{rankingManagerBean.criteria}">
                        <f:selectItem itemLabel="-- Select One --" itemValue=""/>
                        <f:selectItem itemLabel="Overall Rating" itemValue="Overall Rating"/>
                        <f:selectItem itemLabel="Price" itemValue="Price"/>
                        <f:selectItem itemLabel="Actual Lead Time" itemValue="Actual Lead Time"/>
                    </h:selectOneMenu>
                    <h:outputText value=""/>
                    
                    <p:commandButton image="ui-icon ui-icon-note" value="View Rankings" actionListener="#{rankingManagerBean.rankSupplier}" update="viewSupplierListForm"/>
                </h:panelGrid>
                <br/>
                <br/>
                <br/>
                <h:panelGroup id="rankings" rendered="#{(rankingManagerBean.rm.name != '' || rankingManagerBean.rm.name != null) &amp;&amp; (rankingManagerBean.criteria != null)}">
                    <h:outputText value="Supplier Ranking By #{rankingManagerBean.criteria}" style="font-weight: bold; font-size: 110%"/>
                    <p:separator/>
                    <br/>
                    <p:dataTable var="rec" rowIndexVar="rowIndex" value="#{rankingManagerBean.rankings}">
                        
                        <p:column headerText="Ranking" style="width: 20%">
                            <h:outputText value="#{rowIndex + 1}"/>
                        </p:column>
                        
                        <p:column headerText="Supplier Name" style="width: 50%">
                            <h:outputText value="#{rec.supplier.supplierName}"/>
                        </p:column>
                        
                        <p:column headerText="Overall Rating" rendered="#{rankingManagerBean.criteria == 'Overall Rating'}">
                            <h:outputText value="#{rec.overall}"/>
                        </p:column>
                        
                        <p:column headerText="Price" rendered="#{rankingManagerBean.criteria == 'Price'}">
                            <h:outputText value="#{rec.price}"/>
                        </p:column>
                        
                        <p:column headerText="Actual Lead Time" rendered="#{rankingManagerBean.criteria == 'Actual Lead Time'}">
                            <h:outputText value="#{rec.leadtime}">
                                <f:convertNumber pattern="#0.00"/>
                            </h:outputText>
                        </p:column>

                    </p:dataTable>
                </h:panelGroup>
                <br/>
                <br/>
                <br/>
            </p:panel>
            <br/>
            <br/>
            <br/>
        </h:form>

        <p:dialog header="Search Raw Material" widgetVar="rawMaterialDialog" showEffect="fade" hideEffect="fade" resizable="false" modal="true" width="600">
            <h:form id="rawMaterialForm">
                <br/>
                <p:dataTable var="rawMaterial" value="#{rankingManagerBean.allRawMaterial}" emptyMessage="No raw material found with given criteria"  selection="#{rankingManagerBean.rm}" selectionMode="single">

                    <p:column filterBy="#{rawMaterial.name}" 
                              headerText="Raw Material"
                              filterMatchMode="contains">
                        <h:outputText value="#{rawMaterial.name}" />
                    </p:column>

                </p:dataTable>
                <br/>
                <br/>
                <div align="right">
                    <p:commandButton value="Select Raw Material" update="viewSupplierListForm:rawMaterial" oncomplete="rawMaterialDialog.hide()"/>
                </div>
                <br/>
            </h:form>
        </p:dialog>

    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>
